package com.example.layui.service;


import com.example.layui.dao.UserDao;
import com.example.layui.entity.User;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authc.AuthenticationException;
import org.apache.shiro.authc.UsernamePasswordToken;
import org.apache.shiro.subject.Subject;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service
public class UserService {

    @Resource
    private UserDao userDao;

    public void login(String username, String password){
        // 得到用户
        Subject user = SecurityUtils.getSubject();

        // 创建用户名和密码的验证方式的token
        UsernamePasswordToken token = new UsernamePasswordToken(username, password);

        // 登录
        try {
            user.login(token);
            System.out.println("登录成功");
        }catch (AuthenticationException e){
            //e.printStackTrace();
            System.out.println("登录失败");
//            throw new MyException("E1001");
        }
    }

    public User findByUsernamePwd(String userNumber, String pwd){
        return userDao.findByUsernamePwd(userNumber, pwd);
    }
}
